//
//  PlanVM.m
//  WanCaiC8
//
//  Created by tangang on 2018/4/26.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "PlanVM.h"

@implementation PlanVM

- (void)getMyPlanWithUid:(NSString *)uid andLtype:(NSInteger)ltype andWinState:(NSInteger)winState andPageIndex:(NSInteger)pageIndex Success:(SuccessBlock)success andFail:(FailBlock)fail{
    NSLog(@"--->%@--%ld--%ld",uid,ltype,winState);
    [self GET_Field_Url:@"api/Personal/GetPlan" Params:@{@"uid":uid,@"ltype":@(ltype),@"winState":@(winState),@"pageIndex":@(pageIndex),@"pageSize":defaultPageSize} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([PlanModel mj_objectArrayWithKeyValuesArray:[[returnValue objectForKey:@"Data"]objectForKey:@"PageData"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)postBetWithType:(NSInteger)lType andIssue:(NSString *)currentIssue andBetInfo:(NSString *)betInfo Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Plan/Bet" Params:@{@"lType":@(lType),@"currentIssue":currentIssue,@"betInfo":betInfo} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success(returnValue);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getCurrentPlanWithLtype:(NSInteger)ltype Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/AlreadyPostData" Params:@{@"lType":@(ltype)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([BetModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getPlanDataWithLtype:(NSInteger)ltype andPageIndex:(NSInteger)pageIndex andPageSize:(NSInteger)pageSize Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/GetPlanData" Params:@{@"lType":@(ltype),@"pageIndex":@(pageIndex),@"pageSize":@(pageSize)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([PlanRecommendModel mj_objectArrayWithKeyValuesArray:[[returnValue objectForKey:@"Data"] objectForKey:@"PageData"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getLotteryListOfMyPlanWithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Personal/GetLotteryListOfMyPlan" Params:nil successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([PlanModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}


- (void)getExpertListWithLtype:(NSInteger)lType andPlayName:(NSString *)playName andType:(NSInteger)type andPageIndex:(NSInteger)pageIndex WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Plan/GetExpertList" Params:@{@"lType":@(lType),@"playName":playName,@"type":@(type),@"pageIndex":@(pageIndex),@"pageSize":defaultPageSize} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[[returnValue objectForKey:@"Data"]objectForKey:@"PageData"];
            success([ExpertsModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getExpertHotList:(NSInteger)lType andTop:(NSInteger)top WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/GetTopExpertSearch" Params:@{@"lType":@(lType),@"top":@(top)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([ExpertsHotModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getHistoryListWithLtype:(NSInteger)lType WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/GetHistoryExpertSearch" Params:@{@"lType":@(lType)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([ExpertsHotModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)searchExperWithLtype:(NSInteger)lType andNickName:(NSString *)NickName WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Plan/GetExpertSearchList" Params:@{@"lType":@(lType),@"NickName":NickName} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            NSArray *arr=[returnValue objectForKey:@"Data"];
            success([ExpertsHotModel mj_objectArrayWithKeyValuesArray:arr]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)insterHistoryWithUid:(NSString *)uid WithLtype:(NSInteger)ltype{
    [self GET_Field_Url:@"api/Plan/InsertHotSearch" Params:@{@"lType":@(ltype),@"uid":uid} successBlock:nil failBlock:nil];
}

- (void)deleteHistoryWithUid:(NSString *)uid WithLtype:(NSInteger)ltype WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/DeleteHistory" Params:@{@"lType":@(ltype),@"uid":uid} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success(returnValue);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getUserLastPlayWithUid:(NSString *)uid withPlayName:(NSString *)playName WithLtype:(NSInteger)ltype WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Plan/GetUserLastPlay" Params:@{@"uid":uid,@"playName":playName,@"lType":@(ltype)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getUserExceptionalRecordWithUid:(NSString *)uid withTop:(NSInteger)top WithLtype:(NSInteger)ltype WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/GetTipRecord" Params:@{@"uid":uid,@"top":@(top),@"lType":@(ltype)} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([ExceptionalRecordModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)giftCoinWithId:(NSString *)Id andCoin:(NSString *)coin WithSuccess:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/GiftCoin" Params:@{@"id":Id,@"coin":coin} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            if (!([[returnValue objectForKey:@"Code"] intValue]==60018)) {
                [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            }
            fail([returnValue objectForKey:@"Code"],nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getWonderfulCommentId:(NSString *)ID andType:(NSInteger)type andCount:(NSInteger)count andUserId:(NSString *)userId Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Comment/GetWonderfulComment" Params:@{@"id":ID,@"type":[NSNumber numberWithInteger:type],@"count":[NSNumber numberWithInteger:count],@"RefUserId":userId} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([CommentModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)publishWithId:(NSString *)ID andType:(NSInteger)type andContent:(NSString *)Content andCommentType:(NSInteger)CommentType andUserId:(NSString *)userId andPic:(NSArray *)pic Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Comment/Publish" Params:@{@"Id":ID,@"Type":[NSNumber numberWithInteger:type],@"CommentType":[NSNumber numberWithInteger:CommentType],@"Content":Content,@"Pictures":pic,@"RefUserId":userId} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            [SVProgressHUD showSuccessWithStatus:[returnValue objectForKey:@"Desc"]];
            success([CommentModel mj_objectWithKeyValues:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getCommentListWithId:(NSString *)ID andType:(NSInteger)type andLast:(NSString *)lastId andPageSize:(NSInteger)pageSize andUserId:(NSString *)userId Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Comment/GetCommentList" Params:@{@"id":ID,@"type":[NSNumber numberWithInteger:type],@"lastId":lastId,@"pageSize":[NSNumber numberWithInteger:pageSize],@"RefUserId":userId} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([CommentModel mj_objectArrayWithKeyValuesArray:[returnValue objectForKey:@"Data"]]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getCommentCountWithId:(NSString *)ID andType:(NSInteger)type andUserId:(NSString *)userId Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Comment/GetCommentCount" Params:@{@"id":ID,@"type":[NSNumber numberWithInteger:type],@"RefUserId":userId} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getLastPlayWithUid:(NSString *)uid andLType:(NSInteger)lType andPlayName:(NSString *)playName andIssue:(NSString *)issue Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self POST_Field_Url:@"api/Plan/GetLastPlay" Params:@{@"uid":uid,@"lType":[NSNumber numberWithInteger:lType],@"playName":playName,@"issue":issue} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            if (!([[returnValue objectForKey:@"Code"] intValue]==60018)) {
                [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            }
            fail([returnValue objectForKey:@"Code"],nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getLastPlanWithUid:(NSString *)uid andLType:(NSInteger)lType andPlayName:(NSString *)playName andIssue:(NSString *)issue Success:(SuccessBlock)success andFail:(FailBlock)fail;{
    [self GET_Field_Url:@"api/Plan/GetLastPlan" Params:@{@"uid":uid,@"lType":[NSNumber numberWithInteger:lType],@"playName":playName,@"issue":issue} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            if (!([[returnValue objectForKey:@"Code"] intValue]==60018)) {
                [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            }
            fail([returnValue objectForKey:@"Code"],nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

- (void)getReadCoinWithUid:(NSString *)userId andLType:(NSInteger)lType Success:(SuccessBlock)success andFail:(FailBlock)fail{
    [self GET_Field_Url:@"api/Plan/GetReadCoin" Params:@{@"userId":userId,@"lType":[NSNumber numberWithInteger:lType]} successBlock:^(id returnValue) {
        if ([[returnValue objectForKey:@"Code"] intValue]==APIResponseStutusSuccess) {
            success([returnValue objectForKey:@"Data"]);
        }else{
            [SVProgressHUD showErrorWithStatus:[returnValue objectForKey:@"Desc"]];
            fail(nil,nil);
        }
    } failBlock:^(NSString *errorMessage, NSError *error) {
        [SVProgressHUD showErrorWithStatus:errorMessage];
        fail(nil,nil);
    }];
}

static PlanVM *n_manager=nil;
+ (PlanVM *)manage{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        n_manager=[[PlanVM alloc]init];
    });
    return n_manager;
}
@end
